'''
个人资料类页面
'''

from selenium.webdriver.common.by import By
from page.base_page import BasePage
from selenium.webdriver.support.select import Select

class PersonDataPage(BasePage):

    # 定位器
    gerenziliao_btn_locator = (By.LINK_TEXT, "个人资料")
    bumen_select_locator = (By.ID, 'department')
    gangwei_select_locator = (By.ID, 'role')
    youxiang_locator = (By.CSS_SELECTOR,
                        'body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(11) > td:nth-child(2) > input')
    shouji_locator = (By.NAME, 'telephone')
    baocun_locator = (By.CSS_SELECTOR,
                      "body > div.container > div.row > div:nth-child(2) > form > table > tfoot > tr > td:nth-child(2) > input.btn.btn-primary")
    name_locator = (By.NAME, "name")
    mima_locator = (By.ID, "password")
    xingbie_locator = (By.XPATH, "/html/body/div[5]/div[2]/div[2]/form/table/tbody/tr[10]/td[2]/input[1]")
    dizhi_locator = (By.NAME, "address")
    quxiao_btn_locator = (By.CSS_SELECTOR, "[value=取消]")
    tishixiaoxi_locator = (By.XPATH, "/html/body/div[5]/div[2]/div[1]/div")
    duanyan_xg_youxiang =(By.CSS_SELECTOR,'body > div.container > div.row > div:nth-child(2) > form > table > tbody > tr:nth-child(11) > td:nth-child(2) > input')


    # 点击进入个人资料
    def grzl_into(self):
        self.driver.find_element(*self.gerenziliao_btn_locator).click()
    # 输入用户名
    def grzl_xiugai_yhm(self,name):
        self.driver.find_element(*self.name_locator).clear()
        self.driver.find_element(*self.name_locator).send_keys(name)

    # 输入密码
    def grzl_xiugai_mm(self,mima):
        self.driver.find_element(*self.mima_locator).send_keys(mima)
        
    # 选择部门
    def grzl_xiugai_bm(self):
        bumen=self.driver.find_element(*self.bumen_select_locator)
        Select(bumen).select_by_index(1)

    # 选择岗位
    def grzl_xiugai_gw(self):
        gangwei=self.driver.find_element(*self.gangwei_select_locator)
        Select(gangwei).select_by_index(1)

    # 选择性别
    def grzl_xiugai_xb(self):
        self.driver.find_element(*self.xingbie_locator).click()

    # 输入邮箱
    def grzl_xiugai_yx(self,youxiang):
        self.driver.find_element(*self.youxiang_locator).clear()
        self.driver.find_element(*self.youxiang_locator).send_keys(youxiang)
    
    # 输入手机
    def grzl_xiugai_sj(self,shouji):
        self.driver.find_element(*self.shouji_locator).clear()
        self.driver.find_element(*self.shouji_locator).send_keys(shouji)
    
    # 输入地址
    def grzl_xiugai_dz(self,dizhi):
        self.driver.find_element(*self.dizhi_locator).clear()
        self.driver.find_element(*self.dizhi_locator).send_keys(dizhi)
        
    # 点击保存
    def grzl_baocun(self):
        self.driver.find_element(*self.baocun_locator).click()
    
    # 点击取消
    def grzl_quxiao(self):
        self.driver.find_element(*self.quxiao_btn_locator).click()

    # 获取url地址
    def get_current_url(self):
        return self.driver.current_url
    # 查看修改成功文本
    def get_text(self):
        return self.driver.find_element(*self.tishixiaoxi_locator).text

    # 获取弹窗文本
    def get_tanchaung_text(self):
        return self.driver.switch_to.alert.text

    # 断言表格元素
    def grzl_duanyan_biaoge(self):
        dyg = self.driver.find_element(*self.duanyan_xg_youxiang)
        dy = dyg.get_attribute('class')
        return dy